import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/user',
    name: 'User',
    component: ()=>import("@/views/User")
  },
  {
    path: '/',
    name: 'MainLayout',
    component: () => import("@/views/MainLayout")
  },
  {
    path: '/login',
    name: 'Login',
    beforeEnter:(to,from)=>{
      console.log(from);
      console.log(to);
      if(sessionStorage.getItem("user")){
        window.sessionStorage.clear();
        window.localStorage.clear();
        window.location.reload();
      }
    },
    component: () => import("@/views/Login"),

  },
  {
    path: '/register',
    name: 'Register',
    component: () => import("@/views/Register")
  },
  {
    path: '/index',
    redirect: '/login'
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
});
// router.afterEach(function(to){
//   if(to.path==='/login'){
//     window.location.reload();
//   }
// })

export default router
